#include<bits/stdc++.h>
using namespace std;

struct node
{
	int x, y, step;
};

int m, n;
char maze[60][60];
int vis[60][60];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

void bfs(int &cnt)
{
	queue<node> q;
	q.push({1, 1, 0});
	vis[1][1] = 1;
	
	while(!q.empty())
	{
		node t = q.front();
		q.pop();
		if(t.x == m && t.y == n)
		{
			cnt = t.step;
			return ;
		}
		for(int i = 0;i < 4;i++)
		{
			int xx = t.x+dx[i];
			int yy = t.y+dy[i];
			if(xx > 0 && xx <= m && yy > 0 && yy <= n && !vis[xx][yy] && maze[xx][yy] == '.')
			{
				q.push({xx, yy, t.step+1});
				vis[xx][yy] = 1;
			}
		}
	}
}

int main()
{
	cin>>m>>n;
	for(int i = 1;i <= m;i++)
		for(int j = 1;j <= n;j++)
			cin>>maze[i][j];
	int cnt = 0;
	bfs(cnt);
	cout<<cnt+1;
    return 0;
}

